package org.springblade.upgrade.record.service.impl;

import org.springblade.upgrade.record.entity.UpgradeRecord;
import org.springblade.upgrade.record.model.UpgradeRecordBean;
import org.springblade.upgrade.record.mapper.UpgradeRecordMapper;
import org.springblade.upgrade.record.service.IUpgradeRecordService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;

import java.util.List;

/**
 * @Version 1.0
 */
@Service
public class UpgradeRecordServiceImpl extends BaseServiceImpl<UpgradeRecordMapper, UpgradeRecord> implements IUpgradeRecordService {


	@Override
	@Transactional(rollbackFor = Exception.class)
	public boolean deleteData(UpgradeRecordBean param) throws Exception{
		if(param.getIdList() != null && param.getIdList().size() >0){
			UpdateWrapper<UpgradeRecord> del = new UpdateWrapper<>();
			del.lambda().in(UpgradeRecord::getId, param.getIdList());
			return this.remove(del);
		}
		if (param.getId() != null) {
            return this.removeById(param.getId());
        }
		return true;
	}

	@Override
	public UpgradeRecordBean findBySpec(UpgradeRecordBean param) {
		List<UpgradeRecordBean> list = this.baseMapper.queryList(param);
		if (list == null || list.size() == 0) {
			return null;
		}
		return list.get(0);
	}

	@Override
	public List<UpgradeRecordBean> findListBySpec(UpgradeRecordBean param) {
		return this.baseMapper.queryList(param);
	}

	@Override
	public IPage<UpgradeRecordBean> findPageBySpec(IPage<UpgradeRecordBean> page, UpgradeRecordBean param) {
		List<UpgradeRecordBean> dataList = baseMapper.queryPageList(page, param);
		return page.setRecords(dataList);
	}
}

